{% extends 'base.html' %}
{% load get_item %}
{% block content %}
<h2>订单卡列表</h2>
<a href="/orders/" class="btn btn-secondary">返回订单列表</a>
<a href="/orders/cards/export/{{ order.id }}/" class="btn btn-success">导出Excel</a>

<div style="flex: 1; overflow-x: auto; overflow-y: hidden;">
<table class="table table-bordered mt-3">
                <thead class="table-light">
                    <tr>
                        <th>ICCID</th>
                        <th>MSISDN</th>
                        {% if user.is_superuser or user.profile and user.profile.type == 'admin' %}
                        <th>绑定客户</th>
                        {% endif %}
                        <th>卡状态</th>
                        <th>运营商</th>
                        <th>套餐名称</th>
                        <th>套餐总流量</th>
                        <th>激活时间</th>
                        <th>套餐到期</th>
                    </tr>
                </thead>
                <tbody>
                    {% for card in cards %}
                    <tr style="white-space:nowrap;">
                        <td>{{ card.iccid }}</td>
                        <td>{{ card.msisdn }}</td>
                        {% if user.is_superuser or user.profile and user.profile.type == 'admin' %}
                        <td>
                            {% with rels=card.carduserrelation_set.all %}
                                {% if rels %}
                                    {% for rel in rels %}
                                        {{ rel.customer.username }}
                                    {% endfor %}
                                {% else %}无{% endif %}
                            {% endwith %}
                        </td>
                        {% endif %}
                        <td>{{ card_status_cn|get_item:card.cardStatus|default:card.cardStatus }}</td>
                        <td>{{ operator_cn|get_item:card.operator|default:card.operator }}</td>
                        <td>{{ card.packageName }}</td>
                        <td>{{ card.totalFlow }}</td>
                        <td>{{ card.activateTime }}</td>
                        <td>{{ card.packageTime }}</td>
                    </tr>
                    {% empty %}
                    <tr><td colspan="13" class="text-center">暂无卡信息</td></tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
{% endblock %}
